package com.wx.chapter8.homework13;

/**
 * ClassName:HomeWork13
 * Package :com.wx.chapter8.homework13
 * Description :
 *
 * @Author : coder_mu
 * @Create : 2023/5/29 - 21:37
 */
public class HomeWork13 {
    public static void main(String[] args) {
        Student student1 = new Student("jay", '男', 18, 1);
        Student student2 = new Student("jay2", '男', 29, 1);
        Teacher teacher1 = new Teacher("tim", '男', 20, 8);
        Teacher teacher2 = new Teacher("tim2", '男', 30, 8);
        Person[] people = {student1, student2, teacher1, teacher2};//创建对象存储的数组
        bubbleSort(people);//对数组进行排序
        for (Person item : people) {//数组遍历
            System.out.println(item.toString());
            item.printInfo();//对象信息打印
        }
    }

    //年龄从高到低排序
    public static void bubbleSort(Person[] peoples) {//冒泡排序
        Person temp = null;
        for (int i = 0; i < peoples.length - 1; i++) {
            for (int j = 0; j < peoples.length - 1 - i; j++) {
                //判断条件
                if (peoples[j].getAge() < peoples[j + 1].getAge()) {
                    temp = peoples[j];
                    peoples[j] = peoples[j + 1];
                    peoples[j + 1] = temp;
                }
            }
        }
    }
}
